package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_6_15_Training {
    //改变一个整数能得到的最大差值
    public int maxDiff(int num) {
        String s = String.valueOf(num);
        String t = s;
        int pos = 0;
        int len = s.length();
        while (pos < len && s.charAt(pos) == '9') {
            pos++;
        }
        if (pos < len) {
            s = s.replace(s.charAt(pos), '9');
        }
        if (t.charAt(0) == '1') {
            pos = 1;
            while (pos < len && (t.charAt(pos) == '0' || t.charAt(pos) == '1')) {
                pos++;
            }
            if (pos < len) {
                t = t.replace(t.charAt(pos), '0');
            }
        } else {
            t = t.replace(t.charAt(0), '1');
        }
        return Integer.parseInt(s) - Integer.parseInt(t);
    }
}
